
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>排期内容管理</title>
     <#include "../StaticFile.ftl">
    <script>
    
    

    var toolbar = [{
            text:'新增内容快',
            iconCls:'icon-add',
            handler:function(){global.id=0;$('#dlg_add_content').dialog('open');conent_construct.clean();}
        }];
    
    </script>
</head>
<body>



<div id="cc" class="easyui-layout" style="width:100%;height:900px;">

     <#include "../Head.ftl">
     <#include "../Menu.ftl">
    <div  data-options="region:'center',title:'数据显示区',split:true">
    
   
    <table id="dg" title="内容快列表" style="width:100%" data-options="
                singleSelect:true,
                autoRowHeight:false,
                pagination:true,
                url:'/schedulecontent/getdata?schedule_id=${schedule_id}',
                pageSize:20,toolbar:toolbar">
        <thead>
            <tr>
                <th field="id" width="80" align="center">内容快编号</th>
                <th field="title" width="120" align="center">内容块名称</th>
                 <th data-options="field:'createdate',width:160,align:'center',formatter:formatDateTime" width="160">创建时间</th>
                  <th data-options="field:'page_title',width:80,align:'center'" width="100">页面名称</th>
                <th data-options="field:'schedule_id',width:80,align:'center'">排期id</th>
                <th data-options="field:'schedule_type_name',width:160,align:'center'">内容类型</th>
                <th data-options="field:'schedule_order',width:80,align:'center'">顺序</th>
                <th data-options="field:'operation',width:180,align:'center',formatter:formatOperation" >操作</th>
            </tr>
        </thead>
    </table>
   
   
      
      <div id="dlg_add_content" class="easyui-dialog" title="创建内容块" data-options="iconCls:'icon-save'" style="width:690px;height:590px;padding:10px;">
        
            <table cellpadding="5">
              
                <tr>
                    <td>内容类型:</td>
                    <td>
                    <select class="easyui-combobox" name="type" id="type"  onChange="alert(1)">
                        <option value="1">四列图文</option>
                        <option value="2">一列图片</option>
                        <option value="3">两列图片</option>
                        <option value="4">一列应用</option>
                        <option value="5">三列应用</option>
                        <option value="6">四列图片</option>
                        </select>
                    </td>
                    
                </tr>
                
               <tr>
               <td>标题：</td>
               <td><input class="easyui-textbox" type="text"  id="content" name="content" ></td>
               </tr>
               
                <tr>
               <td>显示顺序：</td>
               <td><input class="easyui-textbox" type="text"  id="schedule_order" name="schedule_order" ></td>
               </tr>
            </table>
            
            <table  id="table_img_text">
             
             <tr>
             
             <td>图片</td>
             <td>文本</td>
             <td>跳转类型</td>
             <td>内容</td>
             
             </tr>
                    <tr id="tr_one">
                    <td style="">
                     <#assign name="content_img_one">
                  <#assign img_flag="0">
                   <#include "../FileUpload.ftl">
                    </td>
                  
                     
                  
                     <td style="">
                     <input class="easyui-textbox" type="text"  id="content_one" name="enname" >
                     </td>
                     <td>
                     <select class="easyui-combobox"  id="content_type_one" name="enname" >
                     <option value="1">链接</option>
                     <option value="2">应用</option>
                      <option value="3">页面</option>
                     <select>
                     </td>
                     <td><input class="easyui-textbox" type="text"  id="content_target_one" name="enname" >
                     </td>
                    </tr>
                      <tr id="tr_two">
                    <td>
                     <#assign name="content_img_two">
                  <#assign img_flag="0">
                   <#include "../FileUpload.ftl">
                    </td>
                  
                     
                  
                     <td style="">
                     <input class="easyui-textbox" type="text"  id="content_two" name="enname" >
                     </td>
                     <td>
                    <select class="easyui-combobox"  id="content_type_two" name="enname" >
                     <option value="1">链接</option>
                     <option value="2">应用</option>
                      <option value="3">页面</option>
                     <select>

                     </td>
                     <td><input class="easyui-textbox" type="text"  id="content_target_two" name="enname" >
                     </td>
                    </tr>
                    <tr id="tr_three">
                    <td >
                     <#assign name="content_img_three">
                  <#assign img_flag="0">
                   <#include "../FileUpload.ftl">
                    </td>
                  
                     
                  
                     <td style="">
                     <input class="easyui-textbox" type="text"  id="content_three" name="enname" >
                     </td>
                     <td>
                     <select class="easyui-combobox"  id="content_type_three" name="enname" >
                      <option value="1">链接</option>
                     <option value="2">应用</option>
                      <option value="3">页面</option>
                     <select>
                     
                     </td>
                     <td><input class="easyui-textbox" type="text"  id="content_target_three" name="enname" >
                     </td>
                    </tr>
                      <tr id="tr_four">
                    <td>
                     <#assign name="content_img_four">
                  <#assign img_flag="0">
                   <#include "../FileUpload.ftl">
                    </td>
                  
                     
                  
                     <td style="">
                     <input class="easyui-textbox" type="text"  id="content_four" name="enname" >
                     </td>
                     <td>
                    <select class="easyui-combobox"  id="content_type_four" name="enname" >
                    <option value="1">链接</option>
                     <option value="2">应用</option>
                      <option value="3">页面</option>
                     <select>

                     </td>
                     <td><input class="easyui-textbox" type="text"  id="content_target_four" name="enname" >
                     </td>
                    </tr>
                 
                    </table>
                    
                    <table id="table_app_list">
                    
               
                    <tr>
                    <td>内容源:</td>
                    <td>
                     <select class="easyui-combobox" name="app_source_content" id="app_source_content">
                         <option value="0">请选择</option>
                        <#list sources as source >
                        <option value="${source.id?long?c}">${source.name}</option>
                        </#list>
                        
                        </select>
                    <tr>
                     <tr>
                    <td>直显数量:</td>
                    <td><input class="easyui-textbox" type="text"  id="app_source_content_num" name="app_source_content" ></td>
                    <tr>
                    </table>
       
         <div style="text-align:center;padding:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addContent()">添加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">取消</a> 
         </div>
        </div>
       
      </div></div>
      
     <script>
     
        function clearForm()
        {
             $('#dlg_add_content').dialog('close');
        }
     
        
     
        function addContent()
        {
        
            
            var data=conent_construct.four_image_text();
            if(data.code==1)
            {
                alert(data.msg);
                return;
            }
            
             if(!window.confirm("确定要保存么？"))
                {
                    return;
                }
             $.ajax({
                type: "POST",
                  url: "/schedulecontent/add",
                  data:data,
                  success:function(data)
                  {
                    //var result=jQuery.parseJSON(data);
                    
                    
                    $('#dlg_add_content').dialog('close');
                    doSearch();
                    
                  }
                  });
        }
        
        
         var conent_construct={
        
            four_image_text:function()
            {
            
          
                data={};
                data.id=global.id;
                data.schedule_id=global.schedule_id;
                data.type=$("#type").combobox("getValue");
                data.title=$("#content").textbox("getValue");
                data.code=0;
                if(!data.title)
                {
                    data.code=1;
                    data.msg="内容标题不能为空";
                    return data;
                }
                data.order=$("#schedule_order").textbox("getValue");
                var reg = /^\d+$/;
               if(!data.order||!reg.test(data.order))
               {
                    data.code=1;
                    data.msg="顺序必须为数字并且不能为空";
                    return data;
               }
                data.source=$("#app_source_content").combobox("getValue");
              
                data.row_num=$("#app_source_content_num").textbox("getValue");
                
                if(data.type>3)
                {
                    if(data.source==0)
                    {
                        data.code=1;
                        data.msg="请选择数据源";
                        return data;
                    }
                    if(!data.row_num||!reg.test(data.row_num))
                    {
                        data.code=1;
                        data.msg="显示数量必须为数字且不为空";
                        return data;
                    }
                }
              
                var Items=[];
                var itemOne={};
                itemOne.text=$("#content_one").textbox("getValue");
                itemOne.target_type=$("#content_type_one").combobox("getValue");
                itemOne.target_url=$("#content_target_one").textbox("getValue");
                itemOne.img=$("#display_img_content_img_one").attr("src");
                
                var itemTwo={};
                itemTwo.text=$("#content_two").textbox("getValue");
                itemTwo.target_type=$("#content_type_two").combobox("getValue");
                itemTwo.target_url=$("#content_target_two").textbox("getValue");
                itemTwo.img=$("#display_img_content_img_two").attr("src");
                
                var itemThree={};
                itemThree.text=$("#content_three").textbox("getValue");
                itemThree.target_type=$("#content_type_three").combobox("getValue");
                itemThree.target_url=$("#content_target_three").textbox("getValue");
                itemThree.img=$("#display_img_content_img_three").attr("src");
                
                 var itemFour={};
                itemFour.text=$("#content_four").textbox("getValue");
                itemFour.target_type=$("#content_type_four").combobox("getValue");
                itemFour.target_url=$("#content_target_four").textbox("getValue");
                itemFour.img=$("#display_img_content_img_four").attr("src");
                
                
                switch( data.type)
                {
                    case "1":
                        if(!itemOne.text||!itemTwo.text||!itemThree.text||!itemFour.text)
                        {
                            data.code=1;
                            data.msg="图文中文本都不能为空";
                            return data;
                        }
                        if(!itemOne.target_url||!itemTwo.target_url||!itemThree.target_url||!itemFour.target_url)
                        {
                            data.code=1;
                            data.msg="图文中内容都不能为空";
                            return data;
                        }
                        
                        if(!itemOne.img||!itemTwo.img||!itemThree.img||!itemFour.img)
                        {
                            data.code=1;
                            data.msg="图文中图片都不能为空";
                            return data;
                        }
                         if((itemOne.target_type==3&&itemOne.target_url==global.page_id)||
                         (itemTwo.target_type==3&&itemTwo.target_url==global.page_id)||
                         (itemThree.target_type==3&&itemThree.target_url==global.page_id)||
                         (itemFour.target_type==3&&itemFour.target_url==global.page_id))
                        {
                            data.code=1;
                            data.msg="不能跳转当前页面";
                            return data;
                        }
                        Items.push(itemOne);
                        Items.push(itemTwo);
                        Items.push(itemThree);
                        Items.push(itemFour);
                    break;
                    case "2":
                        if(!itemOne.text)
                        {
                            data.code=1;
                            data.msg="图文文本都不能为空";
                            return data;
                        }if(!itemOne.target_url)
                        {
                            data.code=1;
                            data.msg="图文中内容都不能为空";
                            return data;
                        }
                         if(!itemOne.img)
                        {
                            data.code=1;
                            data.msg="图文中图片都不能为空";
                            return data;
                        }
                        if((itemOne.target_type==3&&itemOne.target_url==global.page_id))
                        {
                            data.code=1;
                            data.msg="不能跳转当前页面";
                            return data;
                        }
                        Items.push(itemOne);
                    break;
                    case "3":
                    
                    if(!itemOne.text||!itemTwo.text)
                        {
                            data.code=1;
                            data.msg="图文中文本都不能为空";
                            return data;
                        }
                        if(!itemOne.target_url||!itemTwo.target_url)
                        {
                            data.code=1;
                            data.msg="图文中内容都不能为空";
                            return data;
                        }
                        
                        if(!itemOne.img||!itemTwo.img)
                        {
                            data.code=1;
                            data.msg="图文中图片都不能为空";
                            return data;
                        }
                        if((itemOne.target_type==3&&itemOne.target_url==global.page_id)||(itemTwo.target_type==3&&itemTwo.target_url==global.page_id))
                        {
                            data.code=1;
                            data.msg="不能跳转当前页面";
                            return data;
                        }
                        Items.push(itemOne);
                        Items.push(itemTwo);
                        break;
                    default:
                        break;
                }
              
                
                data.resource=JSON.stringify(Items);
                return data;
            },
         
            change_content_display:function(n)
            {
            
                    
                    switch(n)
                    {
                        case "1":
                         $("#table_img_text").show();
                            $("#table_app_list").hide();
                        $("#tr_one").show();
                        $("#tr_two").show();
                        $("#tr_three").show();
                        $("#tr_four").show();   
                        break;
                        case "2":
                          $("#table_img_text").show();
                            $("#table_app_list").hide();
                        $("#tr_one").show();
                        $("#tr_two").hide();
                        $("#tr_three").hide();
                        $("#tr_four").hide();
                        break;
                        
                        case "3":
                          $("#table_img_text").show();
                            $("#table_app_list").hide();
                        $("#tr_one").show();
                        $("#tr_two").show();
                        $("#tr_three").hide();
                        $("#tr_four").hide();
                        break;
                        default:
                            $("#table_img_text").hide();
                            $("#table_app_list").show();
                            break;
                    }
                    
                
            },
            clean:function()
            {
            
                                $("#type").combobox("setValue",1);
                                $("#content").textbox("setValue","");
                                $("#schedule_order").textbox("setValue",0);
                                $("#content_one").textbox("setValue","");
                                $("#content_type_one").combobox("setValue",1);
                                $("#content_target_one").textbox("setValue","");
                                $("#display_img_content_img_one").attr("src","");
                                $("#form_upload_content_img_one").show();
                                $("#form_upload_successful_content_img_one").hide();
                                
                                  $("#content_two").textbox("setValue","");
                                $("#content_type_two").combobox("setValue",1);
                                $("#content_target_two").textbox("setValue","");
                                $("#display_img_content_img_two").attr("src","");
                                $("#form_upload_content_img_two").show();
                                $("#form_upload_successful_content_img_two").hide();
                                
                                
                                  $("#content_three").textbox("setValue","");
                                $("#content_type_three").combobox("setValue",1);
                                $("#content_target_three").textbox("setValue","");
                                $("#display_img_content_img_three").attr("src","");
                                  $("#form_upload_content_img_three").show();
                                $("#form_upload_successful_content_img_three").hide();
                                
                                  $("#content_four").textbox("setValue","");
                                $("#content_type_four").combobox("setValue", 1);
                                $("#content_target_four").textbox("setValue","");
                                $("#display_img_content_img_four").attr("src","");
                                
                                  $("#form_upload_content_img_four").show();
                                $("#form_upload_successful_content_img_four").hide();
                                
                                 $("#app_source_content").combobox("setValue",0);
                                $("#app_source_content_num").textbox("setValue","");
                                
                                this.change_content_display("1");
            }
            
        }
     
          $(function(){
            var pager = $('#dg').datagrid().datagrid('getPager');
            $('#dlg').dialog('close');
            $('#dlg_add_content').dialog('close');
            
            $("#type").combobox({
            
                onChange:function(n,o)
                {
                    conent_construct.change_content_display(n)
                }
            })
             })
               // get the pager of datagrid
               
         function doSearch(){
            $('#dg').datagrid('load',{
         
            });
            }
            var  global={id:0,schedule_id:${schedule_id},page_id:${page_id}};
            /*function addElement()
            {
                
                $.ajax({
                type: "POST",
                  url: "/schedulecontent/add",
                  data:{
                  id:global.id,
                  begintime:$("#begintime").textbox("getValue"),
                  endtime:$("#endtime").textbox("getValue"),
                  page_id:global.schedule_id
                  },
                  success:function(data)
                  {
                    //var result=jQuery.parseJSON(data);
                    
                    doSearch();
                    $('#dlg').dialog('close');
                    
                  }
                  });
            }*/
            
          
        function formatOperation(val,row)
        {
        
           
           
                return '<a href="javascript:void(0)" style="padding-right:10px;" class="easyui-linkbutton"  onclick="editElement('+row.id+')">编辑</a><a href="javascript:void(0)" class="easyui-linkbutton"  onclick="delElement('+row.id+')">删除</a>'
            
          
           
        }
        
         function delElement(id)
            {
             if(!window.confirm("确定要删除么？"))
                {
                    return;
                }
                $.ajax({ type: "GET",
                url: "/schedulecontent/deleteElement?id="+id+"&scheduleId="+global.schedule_id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                        doSearch(); 
                    }
                  }});
            }
        function formatStatus(val,row)
        {
            if(val==0)
            {
                return "正常"
            }
            else
            {
                return "禁用"
            }
        }
        
      
         function formatIcon(val,row)
        {
           return "<img style='high:30px;width:30px' src='"+val+"'/>";
        } 
        
      
        function editElement(id)
        {
              global.id=id;
              $.ajax({ type: "GET",
                url: "/schedulecontent/getelement?id="+id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                        conent_construct.clean();
                        var type=returnData.data.schedule_type_id.toString();
                        $("#type").combobox("setValue",type);
                        $("#content").textbox("setValue",returnData.data.title);
                         $("#schedule_order").textbox("setValue",returnData.data.schedule_order);
                        conent_construct.change_content_display(type);
                        switch(type)
                        {
                            case "1":
                                $("#content_one").textbox("setValue",returnData.data.pictures[0].title);
                                $("#content_type_one").combobox("setValue",returnData.data.pictures[0].intent_type);
                                $("#content_target_one").textbox("setValue",returnData.data.pictures[0].intent_data);
                                $("#display_img_content_img_one").attr("src",returnData.data.pictures[0].url);
                                $("#form_upload_content_img_one").hide();
                                $("#form_upload_successful_content_img_one").show();
                                
                                  $("#content_two").textbox("setValue",returnData.data.pictures[1].title);
                                $("#content_type_two").combobox("setValue",returnData.data.pictures[1].intent_type);
                                $("#content_target_two").textbox("setValue",returnData.data.pictures[1].intent_data);
                                $("#display_img_content_img_two").attr("src",returnData.data.pictures[1].url);
                                $("#form_upload_content_img_two").hide();
                                $("#form_upload_successful_content_img_two").show();
                                
                                
                                  $("#content_three").textbox("setValue",returnData.data.pictures[2].title);
                                $("#content_type_three").combobox("setValue",returnData.data.pictures[2].intent_type);
                                $("#content_target_three").textbox("setValue",returnData.data.pictures[2].intent_data);
                                $("#display_img_content_img_three").attr("src",returnData.data.pictures[2].url);
                                  $("#form_upload_content_img_three").hide();
                                $("#form_upload_successful_content_img_three").show();
                                
                                  $("#content_four").textbox("setValue",returnData.data.pictures[3].title);
                                $("#content_type_four").combobox("setValue",returnData.data.pictures[3].intent_type);
                                $("#content_target_four").textbox("setValue",returnData.data.pictures[3].intent_data);
                                $("#display_img_content_img_four").attr("src",returnData.data.pictures[3].url);
                                
                                  $("#form_upload_content_img_four").hide();
                                $("#form_upload_successful_content_img_four").show();
                
                                break;
                            case "2":
                              $("#content_one").textbox("setValue",returnData.data.pictures[0].title);
                                $("#content_type_one").combobox("setValue",returnData.data.pictures[0].intent_type);
                                $("#content_target_one").textbox("setValue",returnData.data.pictures[0].intent_data);
                                $("#display_img_content_img_one").attr("src",returnData.data.pictures[0].url);
                                 $("#form_upload_content_img_one").hide();
                                $("#form_upload_successful_content_img_one").show();
                                break;
                            case "3":
                             $("#content_one").textbox("setValue",returnData.data.pictures[0].title);
                                $("#content_type_one").combobox("setValue",returnData.data.pictures[0].intent_type);
                                $("#content_target_one").textbox("setValue",returnData.data.pictures[0].intent_data);
                                $("#display_img_content_img_one").attr("src",returnData.data.pictures[0].url);
                                 $("#form_upload_content_img_one").hide();
                                $("#form_upload_successful_content_img_one").show();
                                
                                $("#content_two").textbox("setValue",returnData.data.pictures[1].title);
                                $("#content_type_two").combobox("setValue",returnData.data.pictures[1].intent_type);
                                $("#content_target_two").textbox("setValue",returnData.data.pictures[1].intent_data);
                                $("#display_img_content_img_two").attr("src",returnData.data.pictures[1].url);
                                 $("#form_upload_content_img_two").hide();
                                $("#form_upload_successful_content_img_two").show();
                                break;
                             default:
                                
                             $("#app_source_content").combobox("setValue",returnData.data.content);
                             $("#app_source_content_num").textbox("setValue",returnData.data.row_num);
                             break;
                        }
                        
                      
                    }
              
                  }});
                    $('#dlg_add_content').dialog('open');
                  
        }
        
        function formatDateTime(val,row)
        {
            
             return formatTime(val);
        }
    </script>
    
</body>
</html>